package com.zzmcc.jms.controller;

import com.jfinal.aop.Before;
import com.jfinal.ext.render.excel.PoiRender;
import com.jfinal.log.Logger;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.zzmcc.base.BaseController;
import com.zzmcc.common.AuthorizeInterceptor;
import com.zzmcc.jms.model.*;
import util.ChristStringUtil;

import com.jfinal.ext.kit.PoiKit.Pair;
import com.jfinal.ext.kit.PoiKit.SheetData;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.zzmcc.jms.common.ModelConfigWms.TABLE_Tower;


public class TowerInfoController extends BaseController {
    private static final Logger log =  Logger.getLogger(TowerInfoController.class);
	@Before(AuthorizeInterceptor.class)
	public void index() {
        StringBuffer whee = new StringBuffer();
        List<Object> param = new ArrayList<Object>();
        String name = getPara("tower.name");
		String addr_code = getPara("tower.addr_code");
		String entry = getPara("tower.entry");
		String owner = getPara("tower.owner");
		String entryer = getPara("tower.entryer");
        String beginDate = getPara("beginDate");
		String endDate = getPara("endDate");
		String home_county = getPara("tower.home_county");
		String image = getPara("tower.image");
		//高级搜索
		String addr_codes =getPara("addr_codes");
		if(ChristStringUtil.isNotEmpty(addr_codes)){
			String[] coderArr = ChristStringUtil.toArray(addr_codes, ",");
			int i=0;
			whee.append(" and addr_code in (\"");
			for (String code : coderArr) {
				i+=1;
				whee.append(code);
				if(i < coderArr.length)
					whee.append("\",\"");

			}
			whee.append("\")");
			System.out.print(whee);

		}

        if(ChristStringUtil.isNotEmpty(name)){
            whee.append(" and name like ?");
            param.add("%" + name + "%");
        }
		if(ChristStringUtil.isNotEmpty(addr_code)){
			whee.append(" and addr_code like ?");
			param.add("%" + addr_code + "%");
		}
		if(ChristStringUtil.isNotEmpty(entryer)){
			whee.append(" and entryer like ?");
			param.add("%" + entryer + "%");
		}
		if(ChristStringUtil.isNotEmpty(entry)){
			whee.append(" and entry = ?");
			param.add(entry);
		}
		if(ChristStringUtil.isNotEmpty(owner)){
			whee.append(" and owner = ?");
			param.add(owner);
		}
		if(ChristStringUtil.isNotEmpty(home_county)){
			whee.append(" and home_county = ?");
			param.add(home_county);
		}
        if(ChristStringUtil.isNotEmpty(beginDate)){
            whee.append(" and TO_DAYS(entryDate) >= TO_DAYS(?)");
            param.add( beginDate );
        }
		if(ChristStringUtil.isNotEmpty(endDate)){
			whee.append(" and TO_DAYS(entryDate) <= TO_DAYS(?)");
			param.add(endDate);
		}
		if(ChristStringUtil.isNotEmpty(image)){
			whee.append(" and image = ?");
			param.add(image);
		}

		Page<Tower> pager = Tower.dao.paginate(
				getParaToInt("pageNum", 1),
				getParaToInt("numPerPage", 20),
                "select * ",
                " from " + TABLE_Tower +" where 1=1 "+ whee.toString()+"order by entryDate desc",
                param.toArray());

		setAttr("pager",pager);
		setAttr("name",name);
		setAttr("addr_code",addr_code);
		setAttr("entryer",entryer);
		setAttr("owner",owner);
		setAttr("entry",entry);
		setAttr("beginDate",beginDate);
		setAttr("endDate",endDate);
		setAttr("home_county",home_county);
		setAttr("image",image);
		render("../tower_info_list.html");
	}

	public void search() {
		render("../tower_info_search.html");
	}

	public void export(){
		//导出条件
		StringBuffer whee = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		String name = getPara("tower.name");

		String addr_code = getPara("tower.addr_code");
		String entry = getPara("tower.entry");
		String owner = getPara("tower.owner");
		String entryer = getPara("tower.entryer");
		String beginDate = getPara("beginDate");
		String endDate = getPara("endDate");
		String home_county = getPara("tower.home_county");
		String image = getPara("tower.image");

		//高级搜索
		String addr_codes =getPara("addr_codes");
		if(ChristStringUtil.isNotEmpty(addr_codes)){
			String[] coderArr = ChristStringUtil.toArray(addr_codes, ",");
			int i=0;
			whee.append(" and addr_code in (\"");
			for (String code : coderArr) {
				i+=1;
				whee.append(code);
				if(i < coderArr.length)
					whee.append("\",\"");

			}
			whee.append("\")");
			System.out.print(whee);

		}

		if(ChristStringUtil.isNotEmpty(name)){
			whee.append(" and name like ?");
			param.add("%" + name + "%");
		}
		if(ChristStringUtil.isNotEmpty(addr_code)){
			whee.append(" and addr_code like ?");
			param.add("%" + addr_code);
		}
		if(ChristStringUtil.isNotEmpty(entryer)){
			whee.append(" and entryer like ?");
			param.add("%" + entryer + "%");
		}
		if(ChristStringUtil.isNotEmpty(entry)){
			whee.append(" and entry = ?");
			param.add(entry);
		}
		if(ChristStringUtil.isNotEmpty(owner)){
			whee.append(" and owner = ?");
			param.add(owner);
		}
		if(ChristStringUtil.isNotEmpty(home_county)){
			whee.append(" and home_county = ?");
			param.add(home_county);
		}
		if(ChristStringUtil.isNotEmpty(beginDate)){
			whee.append(" and TO_DAYS(entryDate) >= TO_DAYS(?)");
			param.add( beginDate );
		}
		if(ChristStringUtil.isNotEmpty(endDate)){
			whee.append(" and TO_DAYS(entryDate) <= TO_DAYS(?)");
			param.add(endDate);
		}
		if(ChristStringUtil.isNotEmpty(image)){
			whee.append(" and image = ?");
			param.add(image);
		}

		//1.站点信息
		List<Record> column1s = Db.find("show full columns from Tower_info_1");
		String sql = "select b.* from jms_tower a inner join Tower_info_1 b on a.addr_code=b.c where 1=1 "+ whee.toString();
		List<Record> info1s =Db.find(sql,param.toArray());
		List<Pair> title1s = new ArrayList<Pair>();
		for(Record column : column1s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title1s.add(new Pair(key, value));
		}
		String sheet1Name ="站点信息";
		SheetData sheet1Data = new SheetData(title1s,info1s,sheet1Name);

		//2.机房内容
		List<Record> column2s = Db.find("show full columns from Tower_info_2");
		sql = "select b.* from Tower_info_2 b inner join jms_tower a on b.c=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info2s =Db.find(sql,param.toArray());

		List<Pair> title2s = new ArrayList<Pair>();
		for(Record column : column2s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title2s.add(new Pair(key, value));
		}
		String sheet2Name ="机房内容";
		SheetData sheet2Data = new SheetData(title2s,info2s,sheet2Name);

		//3.机房检查信息
		List<Record> column3s = Db.find("show full columns from Tower_info_3");
		sql = "select b.* from Tower_info_3 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info3s =Db.find(sql,param.toArray());
		List<Pair> title3s = new ArrayList<Pair>();
		for(Record column : column3s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title3s.add(new Pair(key, value));
		}
		String sheet3Name ="机房检查信息";
		SheetData sheet3Data = new SheetData(title3s,info3s,sheet3Name);

		//4.铁塔基础资料
		List<Record> column4s = Db.find("show full columns from Tower_info_4");
		sql = "select b.* from Tower_info_4 b inner join jms_tower a on b.c=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info4s =Db.find(sql,param.toArray());
		List<Pair> title4s = new ArrayList<Pair>();
		for(Record column : column4s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title4s.add(new Pair(key, value));
		}
		String sheet4Name ="铁塔基础资料";
		SheetData sheet4Data = new SheetData(title4s,info4s,sheet4Name);

		//5.楼面塔抱杆检查信息
		List<Record> column5s = Db.find("show full columns from Tower_info_5");
		sql = "select b.* from Tower_info_5 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info5s =Db.find(sql,param.toArray());
		List<Pair> title5s = new ArrayList<Pair>();
		for(Record column : column5s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title5s.add(new Pair(key, value));
		}
		String sheet5Name ="楼面塔抱杆检查信息";
		SheetData sheet5Data = new SheetData(title5s,info5s,sheet5Name);

		//6.铁塔检查信息
		List<Record> column6s = Db.find("show full columns from Tower_info_6");
		sql = "select b.* from Tower_info_6 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info6s =Db.find(sql,param.toArray());
		List<Pair> title6s = new ArrayList<Pair>();
		for(Record column : column6s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title6s.add(new Pair(key, value));
		}
		String sheet6Name ="铁塔检查信息";
		SheetData sheet6Data = new SheetData(title6s,info6s,sheet6Name);


		//7.蓄电池
		List<Record> column7s = Db.find("show full columns from Tower_info_7");
		sql = "select b.* from Tower_info_7 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info7s =Db.find(sql,param.toArray());
		List<Pair> title7s = new ArrayList<Pair>();
		for(Record column : column7s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title7s.add(new Pair(key, value));
		}
		String sheet7Name ="蓄电池";
		SheetData sheet7Data = new SheetData(title7s,info7s,sheet7Name);

		//8.开关电源
		List<Record> column8s = Db.find("show full columns from Tower_info_8");
		sql = "select b.* from Tower_info_8 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info8s =Db.find(sql,param.toArray());
		List<Pair> title8s = new ArrayList<Pair>();
		for(Record column : column8s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title8s.add(new Pair(key, value));
		}
		String sheet8Name ="开关电源";
		SheetData sheet8Data = new SheetData(title8s,info8s,sheet8Name);

		//9.外市电引入
		List<Record> column9s = Db.find("show full columns from Tower_info_9");
		sql = "select b.* from Tower_info_9 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info9s =Db.find(sql,param.toArray());
		List<Pair> title9s = new ArrayList<Pair>();
		for(Record column : column9s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title9s.add(new Pair(key, value));
		}
		String sheet9Name ="外市电引入";
		SheetData sheet9Data = new SheetData(title9s,info9s,sheet9Name);

		//10.交流配电箱（配电屏）-低压配电设备
		List<Record> column10s = Db.find("show full columns from Tower_info_10");
		sql = "select b.* from Tower_info_10 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info10s =Db.find(sql,param.toArray());
		List<Pair> title10s = new ArrayList<Pair>();
		for(Record column : column10s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title10s.add(new Pair(key, value));
		}
		String sheet10Name ="交流配电箱（配电屏）-低压配电设备";
		SheetData sheet10Data = new SheetData(title10s,info10s,sheet10Name);

		//11.直流配电设备
		List<Record> column11s = Db.find("show full columns from Tower_info_11");
		sql = "select b.* from Tower_info_11 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info11s =Db.find(sql,param.toArray());
		List<Pair> title11s = new ArrayList<Pair>();
		for(Record column : column11s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title11s.add(new Pair(key, value));
		}
		String sheet11Name ="直流配电设备";
		SheetData sheet11Data = new SheetData(title11s,info11s,sheet11Name);

		//12.空调
		List<Record> column12s = Db.find("show full columns from Tower_info_12");
		sql = "select b.* from Tower_info_12 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info12s =Db.find(sql,param.toArray());
		List<Pair> title12s = new ArrayList<Pair>();
		for(Record column : column12s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title12s.add(new Pair(key, value));
		}
		String sheet12Name ="空调";
		SheetData sheet12Data = new SheetData(title12s,info12s,sheet12Name);

		//13.油机
		List<Record> column13s = Db.find("show full columns from Tower_info_13");
		sql = "select b.* from Tower_info_13 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info13s =Db.find(sql,param.toArray());
		List<Pair> title13s = new ArrayList<Pair>();
		for(Record column : column13s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title13s.add(new Pair(key, value));
		}
		String sheet13Name ="油机";
		SheetData sheet13Data = new SheetData(title13s,info13s,sheet13Name);


		//14.变压器或调压器
		List<Record> column14s = Db.find("show full columns from Tower_info_14");
		sql = "select b.* from Tower_info_14 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info14s =Db.find(sql,param.toArray());
		List<Pair> title14s = new ArrayList<Pair>();
		for(Record column : column14s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title14s.add(new Pair(key, value));
		}
		String sheet14Name ="变压器或调压器";
		SheetData sheet14Data = new SheetData(title14s,info14s,sheet14Name);


		//15.其他设备
		List<Record> column15s = Db.find("show full columns from Tower_info_15");
		sql = "select b.* from Tower_info_15 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info15s =Db.find(sql,param.toArray());
		List<Pair> title15s = new ArrayList<Pair>();
		for(Record column : column15s) {
			String value = column.get("Field");
			String key = column.get("Field");
			title15s.add(new Pair(key, value));
		}
		String sheet15Name ="其他设备";
		SheetData sheet15Data = new SheetData(title15s,info15s,sheet15Name);

		PoiRender excel = PoiRender.me(sheet1Data,sheet2Data,sheet3Data,sheet4Data,sheet5Data,
				sheet6Data,sheet7Data,sheet8Data,sheet9Data,sheet10Data,sheet11Data,sheet12Data,sheet13Data,sheet14Data,sheet15Data);
		render(excel.fileName("tower_info.xls"));

	}

	public void export11(){
		//导出条件
		StringBuffer whee = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		String name = getPara("tower.name");

		String addr_code = getPara("tower.addr_code");
		String entry = getPara("tower.entry");
		String owner = getPara("tower.owner");
		String entryer = getPara("tower.entryer");
		String beginDate = getPara("beginDate");
		String endDate = getPara("endDate");
		String home_county = getPara("tower.home_county");
		String image = getPara("tower.image");

		//高级搜索
		String addr_codes =getPara("addr_codes");
		if(ChristStringUtil.isNotEmpty(addr_codes)){
			String[] coderArr = ChristStringUtil.toArray(addr_codes, ",");
			int i=0;
			whee.append(" and addr_code in (\"");
			for (String code : coderArr) {
				i+=1;
				whee.append(code);
				if(i < coderArr.length)
					whee.append("\",\"");

			}
			whee.append("\")");
			System.out.print(whee);

		}

		if(ChristStringUtil.isNotEmpty(name)){
			whee.append(" and name like ?");
			param.add("%" + name + "%");
		}
		if(ChristStringUtil.isNotEmpty(addr_code)){
			whee.append(" and addr_code like ?");
			param.add("%" + addr_code);
		}
		if(ChristStringUtil.isNotEmpty(entryer)){
			whee.append(" and entryer like ?");
			param.add("%" + entryer + "%");
		}
		if(ChristStringUtil.isNotEmpty(entry)){
			whee.append(" and entry = ?");
			param.add(entry);
		}
		if(ChristStringUtil.isNotEmpty(owner)){
			whee.append(" and owner = ?");
			param.add(owner);
		}
		if(ChristStringUtil.isNotEmpty(home_county)){
			whee.append(" and home_county = ?");
			param.add(home_county);
		}
		if(ChristStringUtil.isNotEmpty(beginDate)){
			whee.append(" and TO_DAYS(entryDate) >= TO_DAYS(?)");
			param.add( beginDate );
		}
		if(ChristStringUtil.isNotEmpty(endDate)){
			whee.append(" and TO_DAYS(entryDate) <= TO_DAYS(?)");
			param.add(endDate);
		}
		if(ChristStringUtil.isNotEmpty(image)){
			whee.append(" and image = ?");
			param.add(image);
		}

		/*
		 *	铁塔物理站址编号表
		 *b序号 c物理站址名称	d物理站址编号	e所在地点	 f站址地理位置经度（度分秒）	g站址地理位置纬度（度分秒）	h覆盖场景 i备注
		 */

		String sql = "select b.b as c,b.c as d,a.addr as e,b.m as f,b.n as g,b.o as h " +
				" from jms_tower a inner join Tower_info_1 b on a.addr_code=b.c where 1=1 "+ whee.toString();
		List<Record> info1s =Db.find(sql,param.toArray());
		List<Pair> title1s = new ArrayList<Pair>();
		title1s.add((new Pair("b","序号")));
		title1s.add((new Pair("c","物理站址名称")));
		title1s.add((new Pair("d","物理站址编号")));
		title1s.add((new Pair("e","所在地点")));
		title1s.add((new Pair("f","站址地理位置经度（度分秒）")));
		title1s.add((new Pair("g","站址地理位置纬度（度分秒）")));
		title1s.add((new Pair("h","覆盖场景")));
		title1s.add((new Pair("i","备注")));
		String sheet1Name ="铁塔物理站址编号表";
		SheetData sheet1Data = new SheetData(title1s,info1s,sheet1Name);
		/*
		*2-1固定资产-自有基站机房
		*
		* b序号	c资产编号或标签号	d资产目录编号	 e物理站址编号 f资产名称	g所在地点
		* h结构形式	i机房建筑面积(平方米)	j启用日期	 k资产责任人	l使用状况 m机房分类
		* n是否为自有局所、自有综合楼、自有营业厅中的一小间	o盘点状态	 p盘点说明	q盘点标签号
		*/

		sql = "select b.id as b,b.d as c,b.c as e,b.b as f,a.addr as g,b.f as h,b.g*b.h as i ,b.r as k,e as l,b.status as n,b.memo as o " +
				" from Tower_info_2 b inner join jms_tower a on b.c=a.addr_code where b.e<>'租赁机房' "+ whee.toString();
		List<Record> info2s =Db.find(sql,param.toArray());
		List<Pair> title2s = new ArrayList<Pair>();
		title2s.add((new Pair("b","序号")));
		title2s.add((new Pair("c","资产编号或标签号")));
		title2s.add((new Pair("d","资产目录编号")));
		title2s.add((new Pair("e","物理站址编号")));
		title2s.add((new Pair("f","资产名称")));
		title2s.add((new Pair("g","所在地点")));
		title2s.add((new Pair("h","结构形式")));
		title2s.add((new Pair("i","机房建筑面积(平方米)")));
		title2s.add((new Pair("j","启用日期")));
		title2s.add((new Pair("k","资产责任人")));
		title2s.add((new Pair("l","使用状况")));
		title2s.add((new Pair("m","机房分类")));
		title2s.add((new Pair("n","是否为自有局所、自有综合楼、自有营业厅中的一小间")));
		title2s.add((new Pair("o","盘点状态")));
		title2s.add((new Pair("p","盘点说明")));
		title2s.add((new Pair("q","盘点标签号")));
		String sheet2Name ="2-1固定资产-自有基站机房";
		SheetData sheet2Data = new SheetData(title2s,info2s,sheet2Name);

		/*
		*2-2固定资产－铁塔
		*
		* b序号	c资产编号或标签号	d资产目录编号	e物理站址编号	f资产名称	 g所在地点
		* h启用日期	i资产责任人	j铁塔形式	 k铁塔类型	l高度(米)	m使用状况 	n维护形式	 o盘点状态	p盘点说明	 q盘点标签号
		*/

		sql = "select b.d as c,b.c as e,a.name as f,a.addr as g,b.e as l,b.status as n,b.memo as o " +
				" from Tower_info_4 b inner join jms_tower a on b.c=a.addr_code where a.property='自有' "+ whee.toString();
		List<Record> info3s =Db.find(sql,param.toArray());
		List<Pair> title3s = new ArrayList<Pair>();
		title3s.add((new Pair("b","序号")));
		title3s.add((new Pair("c","资产编号或标签号")));
		title3s.add((new Pair("d","资产目录编号")));
		title3s.add((new Pair("e","物理站址编号")));
		title3s.add((new Pair("f","资产名称")));
		title3s.add((new Pair("g","所在地点")));
		title3s.add((new Pair("h","启用日期")));
		title3s.add((new Pair("i","资产责任人")));
		title3s.add((new Pair("j","铁塔形式")));
		title3s.add((new Pair("k","铁塔类型")));
		title3s.add((new Pair("l","高度(米)")));
		title3s.add((new Pair("m","使用状况")));
		title3s.add((new Pair("n","维护形式")));
		title3s.add((new Pair("o","盘点状态")));
		title3s.add((new Pair("p","盘点说明")));
		title3s.add((new Pair("q","盘点标签号")));
		String sheet3Name ="2-2固定资产－铁塔";
		SheetData sheet3Data = new SheetData(title3s,info3s,sheet3Name);

		/*
		* 2-3固定资产－电源设备
		* b序号	c资产编号或标签号	d资产目录编号	e物理站址编号	f设备名称	 g所在地点	h规格型号	 i生产厂家	j计量单位	 k数量
		* l启用日期	m使用状况	 n资产责任人	o盘点状态 	p盘点说明	 q盘点标签号
		*
		 */
		sql = "select b.e,b.f,a.addr as g,b.h,b.i,b.k,b.l,b.m  " +
				"from (select   b,b as e ,'开关电源' as f,f as h ,g as i,e as k,t as m,u as l from tower_info_8 " +
				"union all " +
				"select  b,b as e ,'蓄电池' as f,f as h ,g as i,h as k,v as m,w as l from tower_info_7 ) b " +
				"inner join jms_tower a on b.b=a.addr_code where 1=1 " + whee.toString();

		List<Record> info4s =Db.find(sql,param.toArray());
		List<Pair> title4s = new ArrayList<Pair>();
		title4s.add((new Pair("b","序号")));
		title4s.add((new Pair("c","资产编号或标签号")));
		title4s.add((new Pair("d","资产目录编号")));
		title4s.add((new Pair("e","物理站址编号")));
		title4s.add((new Pair("f","设备名称")));
		title4s.add((new Pair("g","所在地点")));
		title4s.add((new Pair("h","规格型号")));
		title4s.add((new Pair("i","生产厂家")));
		title4s.add((new Pair("j","计量单位")));
		title4s.add((new Pair("k","数量")));
		title4s.add((new Pair("l","启用日期")));
		title4s.add((new Pair("m","使用状况")));
		title4s.add((new Pair("n","资产责任人")));
		title4s.add((new Pair("o","盘点状态")));
		title4s.add((new Pair("p","盘点说明")));
		title4s.add((new Pair("q","盘点标签号")));
		String sheet4Name ="2-3固定资产－电源设备";
		SheetData sheet4Data = new SheetData(title4s,info4s,sheet4Name);

		/*
		* 2-4固定资产－空调设备
		* b序号	c资产编号或标签号	d资产目录编号	e物理站址编号	f设备名称	 g所在地点	h规格型号	 i生产厂家	j计量单位	 k数量
		* l启用日期	m使用状况	 n资产责任人	o盘点状态 	p盘点说明	 q盘点标签号
		*
		 */
		sql = "select b.b as e,b.e as f,a.addr as g,b.f as h,b.g as i,b.h as k,b.r as l,b.i as m,b.status as n,b.memo as o " +
				" from Tower_info_12 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info5s =Db.find(sql,param.toArray());
		List<Pair> title5s = new ArrayList<Pair>();
		title5s.add((new Pair("b","序号")));
		title5s.add((new Pair("c","资产编号或标签号")));
		title5s.add((new Pair("d","资产目录编号")));
		title5s.add((new Pair("e","物理站址编号")));
		title5s.add((new Pair("f","设备名称")));
		title5s.add((new Pair("g","所在地点")));
		title5s.add((new Pair("h","规格型号")));
		title5s.add((new Pair("i","生产厂家")));
		title5s.add((new Pair("j","计量单位")));
		title5s.add((new Pair("k","数量")));
		title5s.add((new Pair("l","启用日期")));
		title5s.add((new Pair("m","使用状况")));
		title5s.add((new Pair("n","资产责任人")));
		title5s.add((new Pair("o","盘点状态")));
		title5s.add((new Pair("p","盘点说明")));
		title5s.add((new Pair("q","盘点标签号")));
		String sheet5Name ="2-4固定资产－空调设备";
		SheetData sheet5Data = new SheetData(title5s,info5s,sheet5Name);

		/*
		* 2-5固定资产-其他设备
		* b序号	c资产编号或标签号	d资产目录编号	e物理站址编号	f设备名称	 g所在地点	h规格型号	 i生产厂家	j计量单位	 k数量
		* l启用日期	m使用状况	 n资产责任人	o盘点状态 	p盘点说明	 q盘点标签号
		*
		*/
		sql = "select  b.b as e,b.e as f,a.addr as g,b.g as h,b.h as i,b.i as l,b.f as m,b.status as n,b.memo as o " +
				" from Tower_info_15 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info6s =Db.find(sql,param.toArray());
		List<Pair> title6s = new ArrayList<Pair>();
		title6s.add((new Pair("b","序号")));
		title6s.add((new Pair("c","资产编号或标签号")));
		title6s.add((new Pair("d","资产目录编号")));
		title6s.add((new Pair("e","物理站址编号")));
		title6s.add((new Pair("f","设备名称")));
		title6s.add((new Pair("g","所在地点")));
		title6s.add((new Pair("h","规格型号")));
		title6s.add((new Pair("i","生产厂家")));
		title6s.add((new Pair("j","计量单位")));
		title6s.add((new Pair("k","数量")));
		title6s.add((new Pair("l","启用日期")));
		title6s.add((new Pair("m","使用状况")));
		title6s.add((new Pair("n","资产责任人")));
		title6s.add((new Pair("o","盘点状态")));
		title6s.add((new Pair("p","盘点说明")));
		title6s.add((new Pair("q","盘点标签号")));
		String sheet6Name ="2-5固定资产-其他设备";
		SheetData sheet6Data = new SheetData(title6s,info6s,sheet6Name);

		/*2-6固定资产-外电引入资产
		*b序号	c资产编号或标签号	d资产目录编号	e物理站址编号	f资产名称	 g所在地点
		* h规格型号	i生产厂家 j敷设方式	k计量单位	 l数量
		* m启用日期	n使用状况	 o资产责任人	p盘点状态	 q盘点说明	r盘点标签号
		*/
		sql = "select  b.b as e,a.addr as g,b.f as h,b.e as i,b.l as j,b.status as p,b.memo as q " +
				" from Tower_info_9 b inner join jms_tower a on b.b=a.addr_code where 1=1 "+ whee.toString();
		List<Record> info7s =Db.find(sql,param.toArray());
		List<Pair> title7s = new ArrayList<Pair>();
		title7s.add((new Pair("b","序号")));
		title7s.add((new Pair("c","资产编号或标签号")));
		title7s.add((new Pair("d","资产目录编号")));
		title7s.add((new Pair("e","物理站址编号")));
		title7s.add((new Pair("f","资产名称")));
		title7s.add((new Pair("g","所在地点")));
		title7s.add((new Pair("h","规格型号")));
		title7s.add((new Pair("i","生产厂家")));
		title7s.add((new Pair("j","敷设方式")));
		title7s.add((new Pair("k","计量单位")));
		title7s.add((new Pair("l","数量")));
		title7s.add((new Pair("m","启用日期")));
		title7s.add((new Pair("n","使用状况")));
		title7s.add((new Pair("o","资产责任人")));
		title7s.add((new Pair("p","盘点状态")));
		title7s.add((new Pair("q","盘点说明")));
		title7s.add((new Pair("r","盘点标签号")));
		String sheet7Name ="2-6固定资产-外电引入资产";
		SheetData sheet7Data = new SheetData(title7s,info7s,sheet7Name);

		/*
		* 5-1租赁基站机房
		*
		* b序号	c物理站址编号	d所在地点	 e建筑面积(平方米)	f出租方全称	g是否合租	 h合租方全称
		* i是否有租赁合同	 j租金支付方式	k租赁启始日期	 l租赁终止日期	m租金形式
		* n租金内涵	o是否有续租权	 p使用状况	q机房分类	 r盘点状态	s盘点说明	 t盘点标签号

		*/

		sql = "select  b.c as c ,a.addr as d,b.g*b.h as e " +
				" from Tower_info_2 b inner join jms_tower a on b.c=a.addr_code where b.e='租赁机房' "+ whee.toString();
		List<Record> info8s =Db.find(sql,param.toArray());
		List<Pair> title8s = new ArrayList<Pair>();
		title8s.add((new Pair("b","序号")));
		title8s.add((new Pair("c","物理站址编号")));
		title8s.add((new Pair("d","所在地点")));
		title8s.add((new Pair("e","建筑面积(平方米)")));
		title8s.add((new Pair("f","出租方全称")));
		title8s.add((new Pair("g","是否合租")));
		title8s.add((new Pair("h","合租方全称")));
		title8s.add((new Pair("i","是否有租赁合同")));
		title8s.add((new Pair("j","租金支付方式")));
		title8s.add((new Pair("k","租赁启始日期")));
		title8s.add((new Pair("l","租赁终止日期")));
		title8s.add((new Pair("m","租金形式")));
		title8s.add((new Pair("n","租金内涵")));
		title8s.add((new Pair("o","是否有续租权")));
		title8s.add((new Pair("p","使用状况")));
		title8s.add((new Pair("q","机房分类")));
		title8s.add((new Pair("r","盘点状态")));
		title8s.add((new Pair("s","盘点说明")));
		title8s.add((new Pair("t","盘点标签号")));
		String sheet8Name ="5-1租赁基站机房";
		SheetData sheet8Data = new SheetData(title8s,info8s,sheet8Name);

		PoiRender excel = PoiRender.me(sheet1Data,sheet2Data,sheet3Data,sheet4Data,sheet5Data
				,sheet6Data,sheet7Data,sheet8Data);
		render(excel.fileName("tower_info_11.xls"));

	}

	public void toUpdateEntry() {
		setAttr("tower",Tower.dao.findById(getPara("id")));
		render("../updateEntry.html");
	}
	public void updateEntry() {
		Tower s = getModel(Tower.class, "tower");
		s.update();
		renderDWZSuccessJson("[录入信息]提交成功！");
	}

	/*
		1.站点信息
	 */

	public void add_info_1() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_1 model =Tower_info_1.dao.findFirst("select * from Tower_info_1 where c = ?", addr_code);
		setAttr("t1",model);
		render("../tower_input_1.html");
	}

	public void save_info_1() {
		Tower_info_1 m = getModel(Tower_info_1.class, "t1");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[站点信息]保存成功！");
	}
	public void update_info_1() {

		Tower_info_1 m = getModel(Tower_info_1.class, "t1");
		m.update();
		renderDWZSuccessJson("[站点信息]修改成功！");
	}

	/*
		2.机房内容
	 */
	public void add_info_2() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_2 model =Tower_info_2.dao.findFirst("select * from Tower_info_2 where c = ?", addr_code);
		setAttr("t2",model);
		render("../tower_input_2.html");
	}

	public void save_info_2() {
		Tower_info_2 m = getModel(Tower_info_2.class, "t2");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[机房内容]保存成功！");
	}
	public void update_info_2() {

		Tower_info_2 m = getModel(Tower_info_2.class, "t2");
		m.update();
		renderDWZSuccessJson("[机房内容]修改成功！");
	}

	/*
		3.机房检查信息
	 */
	public void add_info_3() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_3 model =Tower_info_3.dao.findFirst("select * from Tower_info_3 where b = ?", addr_code);
		setAttr("t3",model);
		render("../tower_input_3.html");
	}

	public void save_info_3() {
		Tower_info_3 m = getModel(Tower_info_3.class, "t3");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[机房检查信息]保存成功！");
	}
	public void update_info_3() {

		Tower_info_3 m = getModel(Tower_info_3.class, "t3");
		m.update();
		renderDWZSuccessJson("[机房检查信息]修改成功！");
	}

	/*
		4.铁塔基础资料
	 */
	public void add_info_4() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_4 model =Tower_info_4.dao.findFirst("select * from Tower_info_4 where c = ?", addr_code);
		setAttr("t4",model);
		render("../tower_input_4.html");
	}

	public void save_info_4() {
		Tower_info_4 m = getModel(Tower_info_4.class, "t4");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[铁塔基础资料]保存成功！");
	}
	public void update_info_4() {

		Tower_info_4 m = getModel(Tower_info_4.class, "t4");
		m.update();
		renderDWZSuccessJson("[铁塔基础资料]修改成功！");
	}

	/*
        5.楼面塔抱杆检查信息
    */
	public void add_info_5() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		//关联所属铁塔
		Tower_info_4 t4 = Tower_info_4.dao.findFirst("select * from Tower_info_4 where c = ?", addr_code);
		setAttr("t4",t4);
		Tower_info_5 model =Tower_info_5.dao.findFirst("select * from Tower_info_5 where b = ?", addr_code);
		setAttr("t5",model);
		render("../tower_input_5.html");
	}

	public void save_info_5() {
		Tower_info_5 m = getModel(Tower_info_5.class, "t5");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[楼面塔抱杆检查信息]保存成功！");
	}
	public void update_info_5() {

		Tower_info_5 m = getModel(Tower_info_5.class, "t5");
		m.update();
		renderDWZSuccessJson("[楼面塔抱杆检查信息]修改成功！");
	}

	/*
        6.铁塔检查信息
    */
	public void add_info_6() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		//关联所属铁塔
		Tower_info_4 t4 = Tower_info_4.dao.findFirst("select * from Tower_info_4 where b = ?", addr_code);
		setAttr("t4",t4);
		Tower_info_6 t6 = Tower_info_6.dao.findFirst("select * from Tower_info_6 where b = ?", addr_code);
		setAttr("t6",t6);

		render("../tower_input_6.html");
	}

	public void save_info_6() {
		Tower_info_6 m = getModel(Tower_info_6.class, "t6");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[铁塔检查信息]保存成功！");
	}
	public void update_info_6() {

		Tower_info_6 m = getModel(Tower_info_6.class, "t6");
		m.update();
		renderDWZSuccessJson("[铁塔检查信息]修改成功！");
	}
	public void delete_info_6() {

		String id = getPara("id");

		if(null!=id){
			Tower_info_6.dao.deleteById(id);
		}
		renderDWZSuccessJson("删除成功!");

	}

	/*
        7.蓄电池
    */
	public void info_list_7(){
		Tower tower = Tower.dao.findById(getPara("id"));
		String addr_code = tower.get("addr_code");
		Page<Tower_info_7> pager = Tower_info_7.dao.paginate(
				getParaToInt("pageNum", 1),
				getParaToInt("numPerPage", 20),
				"select * ",
				" from  Tower_info_7 where b = ?",addr_code);
		setAttr("pager",pager);
		render("../tower_info_list_7.html");


	}
	public void add_info_7() {
		String id = getPara("id");
		if(id!=null){
			Tower tower = Tower.dao.findById(id);
			setAttr("tower",tower);
		}
		Tower_info_7 t7 = Tower_info_7.dao.findFirst("select * from Tower_info_7 where id = ?", getParaToInt("t7.id"));
		setAttr("t7",t7);
		render("../tower_input_7.html");
	}

	public void save_info_7() {
		Tower_info_7 m = getModel(Tower_info_7.class, "t7");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[蓄电池]保存成功！");
	}
	public void update_info_7() {

		Tower_info_7 m = getModel(Tower_info_7.class, "t7");
		m.update();
		renderDWZSuccessJson("[蓄电池]修改成功！");
	}

	public void checkIsNotExist(){
		renderJson(checkIsNotExist("Tower_info_7", "id", getPara("t7.id")));
	}

	public void delete_info_7() {

		String[] ids = getParaValues("ids");
		for(String id:ids){
			Tower_info_7.dao.deleteById(id);
		}
		renderDWZSuccessJson("删除成功!");

	}

	/*
        8.开关电源
    */
	public void info_list_8(){
		Tower tower = Tower.dao.findById(getPara("id"));
		String addr_code = tower.get("addr_code");
		Page<Tower_info_8> pager = Tower_info_8.dao.paginate(
				getParaToInt("pageNum", 1),
				getParaToInt("numPerPage", 20),
				"select * ",
				" from  Tower_info_8 where b = ?",addr_code);
		setAttr("pager",pager);
		render("../tower_info_list_8.html");


	}
	public void add_info_8() {
		String id = getPara("id");
		if(id!=null){
			Tower tower = Tower.dao.findById(id);
			setAttr("tower",tower);
		}
		Tower_info_8 t8 = Tower_info_8.dao.findFirst("select * from Tower_info_8 where id = ?", getParaToInt("t8.id"));
		setAttr("t8",t8);

		render("../tower_input_8.html");
	}

	public void save_info_8() {
		Tower_info_8 m = getModel(Tower_info_8.class, "t8");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[开关电源]保存成功！");
	}
	public void update_info_8() {

		Tower_info_8 m = getModel(Tower_info_8.class, "t8");
		m.update();
		renderDWZSuccessJson("[开关电源]修改成功！");
	}

	public void delete_info_8() {

		String[] ids = getParaValues("ids");
		for(String id:ids){
			Tower_info_8.dao.deleteById(id);
		}
		renderDWZSuccessJson("删除成功!");

	}

	/*
        9.外市电引入
    */
	public void add_info_9() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_9 t9 = Tower_info_9.dao.findFirst("select * from Tower_info_9 where b = ?", addr_code);
		setAttr("t9",t9);
		render("../tower_input_9.html");
	}

	public void save_info_9() {
		Tower_info_9 m = getModel(Tower_info_9.class, "t9");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[外市电引入]保存成功！");
	}
	public void update_info_9() {

		Tower_info_9 m = getModel(Tower_info_9.class, "t9");
		m.update();
		renderDWZSuccessJson("[外市电引入]修改成功！");
	}

	/*
        10.交流设备
    */
	public void add_info_10() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_10 t10 = Tower_info_10.dao.findFirst("select * from Tower_info_10 where b = ?", addr_code);
		setAttr("t10",t10);
		render("../tower_input_10.html");
	}

	public void save_info_10() {
		Tower_info_10 m = getModel(Tower_info_10.class, "t10");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[交流设备]保存成功！");
	}
	public void update_info_10() {

		Tower_info_10 m = getModel(Tower_info_10.class, "t10");
		m.update();
		renderDWZSuccessJson("[交流设备]修改成功！");
	}

	/*
        11.直流配电设备
    */
	public void add_info_11() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_11 t11 = Tower_info_11.dao.findFirst("select * from Tower_info_11 where b = ?", addr_code);
		setAttr("t11",t11);
		render("../tower_input_11.html");
	}

	public void save_info_11() {
		Tower_info_11 m = getModel(Tower_info_11.class, "t11");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[直流配电设备]保存成功！");
	}
	public void update_info_11() {

		Tower_info_11 m = getModel(Tower_info_11.class, "t11");
		m.update();
		renderDWZSuccessJson("[直流配电设备]修改成功！");
	}


	/*
        12.空调
    */
	public void info_list_12(){
		Tower tower = Tower.dao.findById(getPara("id"));
		String addr_code = tower.get("addr_code");
		Page<Tower_info_12> pager = Tower_info_12.dao.paginate(
				getParaToInt("pageNum", 1),
				getParaToInt("numPerPage", 20),
				"select * ",
				" from  Tower_info_12 where b = ?", addr_code);
		setAttr("pager",pager);
		render("../tower_info_list_12.html");


	}
	public void add_info_12() {
		String id = getPara("id");
		if(id!=null){
			Tower tower = Tower.dao.findById(id);
			setAttr("tower",tower);
		}
		Tower_info_12 t12 = Tower_info_12.dao.findFirst("select * from Tower_info_12 where id = ?", getParaToInt("t12.id"));
		setAttr("t12",t12);

		render("../tower_input_12.html");
	}

	public void save_info_12() {
		Tower_info_12 m = getModel(Tower_info_12.class, "t12");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[空调]保存成功！");
	}
	public void update_info_12() {

		Tower_info_12 m = getModel(Tower_info_12.class, "t12");
		m.update();
		renderDWZSuccessJson("[空调]修改成功！");
	}

	public void delete_info_12() {

		String[] ids = getParaValues("ids");
		for(String id:ids){
			Tower_info_12.dao.deleteById(id);
		}
		renderDWZSuccessJson("删除成功!");

	}
	/*
        13.油机
    */
	public void add_info_13() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_13 t13= Tower_info_13.dao.findFirst("select * from Tower_info_13 where b = ?", addr_code);
		setAttr("t13",t13);
		render("../tower_input_13.html");
	}

	public void save_info_13() {
		Tower_info_13 m = getModel(Tower_info_13.class, "t13");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[油机]保存成功！");
	}
	public void update_info_13() {

		Tower_info_13 m = getModel(Tower_info_13.class, "t13");
		m.update();
		renderDWZSuccessJson("[油机]修改成功！");
	}

	/*
        14.变压器或调压器
    */
	public void add_info_14() {
		Tower tower = Tower.dao.findById(getPara("id"));
		setAttr("tower",tower);
		String addr_code = tower.get("addr_code");
		Tower_info_14 t14 = Tower_info_14.dao.findFirst("select * from Tower_info_14 where b = ?", addr_code);
		setAttr("t14",t14);
		render("../tower_input_14.html");
	}

	public void save_info_14() {
		Tower_info_14 m = getModel(Tower_info_14.class, "t14");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[变压器或调压器]保存成功！");
	}
	public void update_info_14() {

		Tower_info_14 m = getModel(Tower_info_14.class, "t14");
		m.update();
		renderDWZSuccessJson("[变压器或调压器]修改成功！");
	}

	/*
        15.其他设备
    */
	public void info_list_15(){
		Tower tower = Tower.dao.findById(getPara("id"));
		String addr_code = tower.get("addr_code");
		Page<Tower_info_15> pager = Tower_info_15.dao.paginate(
				getParaToInt("pageNum", 1),
				getParaToInt("numPerPage", 20),
				"select * ",
				" from  Tower_info_15 where b = ?", addr_code);
		setAttr("pager",pager);
		render("../tower_info_list_15.html");


	}
	public void add_info_15() {
		String id = getPara("id");
		if(id!=null){
			Tower tower = Tower.dao.findById(id);
			setAttr("tower",tower);
		}
		Tower_info_15 t15 = Tower_info_15.dao.findFirst("select * from Tower_info_15 where id = ?", getParaToInt("t15.id"));
		setAttr("t15",t15);
		render("../tower_input_15.html");
	}

	public void save_info_15() {
		Tower_info_15 m = getModel(Tower_info_15.class, "t15");
		m.set("createDate", new Date());
		m.save();
		renderDWZSuccessJson("[其他设备]保存成功！");
	}
	public void update_info_15() {

		Tower_info_15 m = getModel(Tower_info_15.class, "t15");
		m.update();
		renderDWZSuccessJson("[其他设备]修改成功！");
	}
	public void delete_info_15() {

		String[] ids = getParaValues("ids");
		for(String id:ids){
			Tower_info_15.dao.deleteById(id);
		}
		renderDWZSuccessJson("删除成功!");

	}
}
